﻿using System.Web.UI;
using System.Web.UI.WebControls;

namespace Demo.SharePoint.WebParts.OfficeLocator
{
    /// <summary>
    /// ITemplate for the Repeater control.
    /// </summary>
    public class OfficeResultsTemplate : ITemplate
    {
        private ListItemType templateType;

        /// <summary>
        /// Initializes a new instance of the <see cref="OfficeResultsTemplate"/> class.
        /// </summary>
        /// <param name="type">The type.</param>
        public OfficeResultsTemplate(ListItemType type)
        {
            templateType = type;
        }

        /// <summary>
        /// When implemented by a class, defines the <see cref="T:System.Web.UI.Control" /> object that child controls and templates belong to. These child controls are in turn defined within an inline template.
        /// </summary>
        /// <param name="container">The <see cref="T:System.Web.UI.Control" /> object to contain the instances of controls from the inline template. </param>
        public void InstantiateIn(Control container)
        {
            PlaceHolder ph = new PlaceHolder { ID = "mainPlaceHolder" };

            switch (templateType)
            {
                case ListItemType.Header:
                    ph.Controls.Add(new LiteralControl("<div><div class=\"stm-officeResultsTitle\">Search Results For: "));
                    ph.Controls.Add(new Label { ID = "lblQuery" });
                    ph.Controls.Add(new LiteralControl("</div>"));
                    break;
                case ListItemType.Item:
                case ListItemType.AlternatingItem:
                    ph.Controls.Add(new LiteralControl(@"
<div style=""padding-bottom: 10px; overflow: hidden;"">
	<div class=""stm-officeResultsTop"">
		<div></div>
	</div>
	<div class=""stm-officeResultsHeadingClosed"" id=""locationResultDetailedHeading@index@"" onmouseover=""this.style.cursor='pointer'"" onclick=""STM_locationResultDetailedHeadingOnClick(@index@)"" style=""overflow: hidden;"">
		<img id=""locationResultDetailedImage@index@"" style=""float: right; padding-left: 5px; padding-right: 10px; padding-top: 3px;"" alt=""Click to Expand Office Information"" title=""Click to Expand Office Information"" src=""_layouts/images/Demo.SharePoint.WebParts/ChevronExpand.gif""/>
		<div style=""font-weight: bold; float: left;"">
"));
                    ph.Controls.Add(new Label { ID = "lblIndex" });
                    ph.Controls.Add(new LiteralControl(@"
		</div>
		<div style=""width: 89%; font-weight: bold; float: left; border-left: 1px solid #000000; padding-left: 5px; margin-left: 5px"">
"));
                    ph.Controls.Add(new Label { ID = "lblOffice" });
                    ph.Controls.Add(new LiteralControl(@"
		</div>
		<div style=""clear: both;""></div>
	</div>
	<div class=""stm-locationResultDetailedContent"" id=""locationResultDetailedContent@index@"" style=""clear: both; display: none;"">
"));
                    ph.Controls.Add(new Label { ID = "lblOfficeDetails" });
                    ph.Controls.Add(new LiteralControl(@"
	</div>
	<div class=""stm-officeResultsBottom"">
		<div></div>
	</div>
</div>
"));
                    break;
                case ListItemType.Footer:
                    ph.Controls.Add(new LiteralControl("</div>"));
                    break;
            }

            container.Controls.Add(ph);
        }
    }
}